<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>菜单添加</title>
		<!-- 导入jquery核心类库 -->
		<script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
		<!-- 导入easyui类库 -->
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css">
		<link rel="stylesheet" type="text/css" href="../../css/default.css">
		<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.portal.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.cookie.js"></script>
		<script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
		<script type="text/javascript">
			$(function(){
			    //页面加载完毕处理两个html之间请求路径的参数,之后请求后台进行数据回显
                var parameter = window.location.search;
                if(parameter != null && parameter != '') {
                    $.get("../../menu/selectMenuById.action" + parameter, function (data) {
                        $("#menuForm").form('load', data);
                        //给下拉框进行回显
                        //$("#pid").combobox('setValue',data.name);
                    });
                }

				// 点击保存
				$('#save').click(function(){
					if($("#menuForm").form('validate')){
					    //获取表单的数据:
						var params = $("#menuForm").serializeJson();
						// 通过校验,使用异步提交数据:
						$.post("../../menu/saveAndUpdate.action",params,function (data) {
							if(data.success){
							    //保存成返回查询页面:
							    window.location.href="menu.html";
							}else{
							    $.messager.alert("警告",data.message,"warning");
							}
                        });
					} else {
						$.messager.alert("提示","数据录入不合法！","warning");
					}
				});
			});

            // 将form请求数据转换为json对象
            $.fn.serializeJson = function(){
                var serializeObj={};
                var array=this.serializeArray();
                var str=this.serialize();
                $(array).each(function(){
                    if(serializeObj[this.name]){
                        if($.isArray(serializeObj[this.name])){
                            serializeObj[this.name].push(this.value);
                        }else{
                            serializeObj[this.name]=[serializeObj[this.name],this.value];
                        }
                    }else{
                        serializeObj[this.name]=this.value;
                    }
                });
                return serializeObj;
            };
		</script>
	</head>

	<body class="easyui-layout">
		<div data-options="region:'north'">
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="javascript:void(0);" class="easyui-linkbutton" plain="true">保存</a>
				<a icon="icon-back" class="easyui-linkbutton" plain="true" href="javascript:history.go(-1);">返回上一页</a>
			</div>
		</div>
		<div data-options="region:'center'">
			<form id="menuForm" method="post" action="../../menu/saveAndUpdate.action">
				<input type="hidden" name="id" />
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">菜单项信息</td>
					</tr>
					<tr>
						<td>名称</td>
						<td>
							<input type="text" name="name" class="easyui-validatebox" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td>访问路径</td>
						<td>
							<input type="text" name="page" />
						</td>
					</tr>
					<tr>
						<td>优先级</td>
						<td>
							<input type="text" name="priority" class="easyui-validatebox" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td>父菜单项</td>
						<td>
							<input name="pid" id="pid" class="easyui-combobox" data-options="valueField:'id',textField:'name',url:'../../menu/menuList.action'" />
						</td>
					</tr>
					<tr>
						<td>描述</td>
						<td>
							<textarea name="description" rows="4" cols="60"></textarea>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</body>

</html>